package git.luohao.controller;

import git.luohao.entity.RouteDefinitionEntity;
import git.luohao.route.RefreshRouteService;
import git.luohao.util.NonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/route")
public class RefreshRouteController {
    @Autowired
    private RefreshRouteService refreshRouteService;

    @GetMapping("/refresh")
    public String refresh() {
        refreshRouteService.refreshRoutes();
        return "已刷新路由表";
    }

    @PostMapping("/addRoute")
    public String addRouteDefinition(@RequestBody RouteDefinitionEntity entity) {
        if (NonUtil.isNon(entity) || NonUtil.isNon(entity.getRouteId())) {
            throw new RuntimeException("缺少必要参数");
        }
        return refreshRouteService.addRoutes(entity);
    }

}
